<#include "/common/_layout.html">
<#assign pageJavascript>
<script type="text/javascript" src="/assets/uploadfive/jquery.uploadifive.min.js"></script>
<script type="text/javascript">
var delit = function(obj){
	var tr = $(obj).parent().parent("tr").attr("id");
	var id = tr.replace("tr_","");
	listPage.deleteTr(tr,id);
};
$(function(){
	$('#excel').uploadifive({
		buttonClass:'btn btn-success',buttonText : '导入',fileSizeLimit : '3000',
	    uploadScript : '/admin/device/device/excelimport',formData:{pid:$('#pid').val()},
	    onUploadComplete : function(file, data) {
	    	layer.msg(data);
	       	$('#myModal').modal('hide');
	    	$("#querybtn").click();
	    }
	});
	$('#importbtn').click(function(){
		$('#myModal').modal('show');
	});
	$("#exportbtn").click(function(){
		$("#extpara").val($(".filter").getFilters());
		$("#extform").submit();
	});
	listPage.config = {listUrl:"/admin/device/device/profile",delUrl:"/admin/device/device/delete"};
	listPage.showlist = function(data){
		if(data.list == undefined) return false;
		$("#showlist").empty();
		$.each(data.list, function (i, row) {
			var stat = ">未激活";
			if(row.stat==1){ stat = "class='warning'>未联网"; }
			else if(row.stat==2){ stat = "class='success'>已联网";}
			var str = '<tr id="tr_'+row.id+'"><td><input value="'+row.id+'" type="checkbox"></td><td>'+row.id+'</td><td>'+(row.sn==null?'':row.sn)+'</td><td>'+row.pname+'</td><td '
				+stat+'</td><td>'+row.intime+'</td><td>'+row.worktime
				+'</td><td><a class="btn btn-xs btn-default" href="/admin/device/device/edit/'+row.id
				+'">编辑</a>&nbsp;<a class="btn btn-xs btn-primary" href="/admin/device/device/bind/'+row.id
				+'">绑定用户</a>&nbsp;<button class="btn btn-xs btn-danger" onclick="delit(this)">删除</button></td></tr>';
			$("#showlist").append(str);
		});
		$("#page").page({total:data.totalRow,currentpage:data.pageNumber,gopage:listPage.gopage,pagesize:data.pageSize});
	};
	$("#querybtn").click(function(){
		listPage.gopage(10,1);
	});
	$("#selectbtn").click(function(){
		if($(this).is(":checked")){
			$(this).parents("table").first().find(":checkbox").prop("checked",true);;
		}
		else{
			$(this).parents("table").first().find(":checkbox").prop("checked",false);;
		}
	});
	$("#delsbtn").click(function(){
		var ids = "";
		$("#showlist").find("input:checked").each(function(){
			ids += "'"+$(this).val()+"',";
		});
		if(ids.length>0){
			listPage.deleteTrs(ids.substr(0,ids.length-1));
		}
	});
	$("#querybtn").click();
});
</script>
</#assign>
<#assign pageCss>
<link rel="stylesheet" type="text/css" href="/assets/uploadfive/uploadifive.css" />
<style type="text/css">
</style>
</#assign>
<@layout pageTitle="设备管理" pageJavascript=pageJavascript pageCss=pageCss>		
<#include "/admin/device/_menu.html"><!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">添加产品</h4>
      </div>
      <div class="modal-body">
      	<form class="form-horizontal" id="modalForm">
			<div class="form-group">
				<label for="deviceProduct.ptype" class="col-sm-2 control-label">设备类型</label>
				<div class="col-sm-5">
					<select class="form-control" id="pid">
			    		<#if plist??>
			    		<#list plist as data>
			    		<option value="${(data.id)!}">${(data.pname)!}</option>
			    		</#list>
			    		</#if>
					</select>
				</div>
			</div><div class="form-group">
				<label class="col-sm-2 control-label">模板下载</label>
				<div class="col-sm-10">
					<a href="/assets/admin/template.xlsx" target="_blank">excel模板</a>
					<p class="help-block">单元格必须为文本格式</p>
				</div>
			</div>
	   </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <input type="file" id="excel">
      </div>
    </div>
  </div>
</div>
<div class="panel panel-default">
  <div class="panel-body filter">
	<div class="form-inline">
		<div class="form-group">
			<p>
			<label for="sn">SN码</label> 
			<input type="text" class="form-control" id="sn" data-rule="like">
			<label for="id">mac地址</label> 
			<input type="text" class="form-control" id="id" data-rule="like">
		    <label for="pid">产品类型：</label>
	    	<select id="pid" data-rule="eq" class="form-control">
	    		<option value="">全部产品</option>
	    		<#if plist??>
	    		<#list plist as data>
	    		<option value="${(data.id)!}">${(data.pname)!}</option>
	    		</#list>
	    		</#if>
	    	</select>
	    	<label>创建时间：</label>
		    <input class="form-control" style="width:160px" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="input" data-rule="ge" id="start_t.intime" >～
			<input class="form-control" style="width:160px" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="input" data-rule="le" id="end_t.intime" >
			</p><p>
	    	<label>激活时间：</label>
		    <input class="form-control" style="width:160px" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="input" data-rule="ge" id="start_t.worktime" >～
			<input class="form-control" style="width:160px" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="input" data-rule="le" id="end_t.worktime" >
			<button id="querybtn" class="btn btn-default">查询</button>
			<a id="addbtn" class="btn btn-info" href="/admin/device/device/edit">新增</a>
			<button id="importbtn" class="btn btn-success">导入设备</button>
			<button id="exportbtn" class="btn btn-warning">导出设备</button>
			<button id="delsbtn" class="btn btn-danger">批量删除</button>
			</p>
		</div>   
	</div>
  </div>
</div>
<form  method="post"  target="_blank" id="extform" action="/admin/device/device/exportexcel" style="display:none">
	<input id="extpara" type="hidden" name="param" value="">
</form>
<table class="table table-bordered table-hover table-striped">
	<thead>
		<tr>
			<th width="30px"><input id="selectbtn" type="checkbox"></th>
			<th>mac地址</th>
			<th>SN码</th>
			<th>产品类型</th>
			<th>状态</th>
			<th>创建时间</th>		
			<th>激活时间</th>		
			<th>操作</th>
		</tr>
	</thead>
	<tbody id="showlist"></tbody>
</table>
<nav><ul id="page" class="pagination"></ul></nav>
</@layout>